package jpa;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RegisterHandler implements IRequestHandler {

	@Override
	public void handleRequest(HttpServletRequest request,
			HttpServletResponse response, IStatelessBean stateless,
			IStatefulBean stateful, ServletContext sc) throws ServletException, IOException 
			
	{	
		
		RequestDispatcher rd;
		
		String userName = request.getParameter("userName"); 
		String password = request.getParameter("password"); 
		String conPass = request.getParameter("conPass"); 
		String email = request.getParameter("email"); 				
		
		
		if(password.equals(conPass))
		{
			stateless.registerUser(userName, password, conPass, email);		
			rd = request.getRequestDispatcher("index.jsp");			
		}	
		else
		{
			rd = request.getRequestDispatcher("registrationFail.jsp");			
		}		
	
		rd.forward(request, response);
		
	}
}


